package com.gxa.dr2.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.dr2.dto.LayDTO;
import com.gxa.dr2.dto.Response;
import com.gxa.dr2.mapper.SalePerformanceDao;
import com.gxa.dr2.param.MyParam;
import com.gxa.dr2.pojo.SalePerformance;
import com.gxa.dr2.service.SalePerformanceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SalePerformanceServiceImpl implements SalePerformanceService {
    @Resource
    private SalePerformanceDao salePerformanceDao;
    @Override
    public int deleteByPrimaryKey(Integer performanceId) {
        return salePerformanceDao.deleteByPrimaryKey(performanceId);
    }

    @Override
    public int deleteByIds(Integer[] ids) {
        for (Integer id:
             ids) {
            salePerformanceDao.deleteByPrimaryKey(id);
        }
        return 1;
    }

    @Override
    public int insert(SalePerformance record) {
        return salePerformanceDao.insert(record);
    }

    @Override
    public int insertSelective(SalePerformance record) {
        return salePerformanceDao.insertSelective(record);
    }

    @Override
    public SalePerformance selectByPrimaryKey(Integer performanceId) {
        return salePerformanceDao.selectByPrimaryKey(performanceId);
    }

    @Override
    public int updateByPrimaryKeySelective(SalePerformance record) {
        return salePerformanceDao.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(SalePerformance record) {
        return 0;
    }

    /**
     * 获得所有员工绩效
     * @return
     */
    /**
     * 员工的列表数据
     * @return
     */
    @Override
    public LayDTO list(MyParam param) {
        // 分页
        PageHelper.startPage(param.getPage(), param.getLimit());
        List<SalePerformance> salePerformances = salePerformanceDao.findByParam(param);
        // 将结果集包装成pageInfo
        PageInfo<SalePerformance> pageInfo = new PageInfo<>(salePerformances);
        return Response.success(pageInfo.getTotal(), pageInfo.getList());
    }
}
